<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>欢迎登录佰晟教育办公管理系统~</title>
    <link rel="stylesheet" th:href="@{assets/libs/layui/css/layui.css}"/>
    <link rel="stylesheet" th:href="@{assets/css/login.css?v=311}">
    <script>
        if (window != top) {
            top.location.replace(location.href);
        }
    </script>
</head>
<body>
<div class="login-wrapper">
    <div class="login-header" style="text-align: center">
        <img th:src="@{assets/images/logo.png}"> 北京佰晟教育办公管理系统
    </div>
    <div class="login-body">
        <div class="layui-card">
            <div class="layui-card-header">
                <i class="layui-icon layui-icon-engine"></i>&nbsp;&nbsp;用户登录
            </div>
            <form class="layui-card-body layui-form layui-form-pane">
             <!--   <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-user"></i></label>
                    <div class="layui-input-block">
                        <select name="city" lay-verify="required">
                            <option value="">请选择登入类型</option>
                            <option value="0" selected>管理员</option>
                            <option value="1">员&nbsp;工</option>
                            <option value="2">加盟商</option>
                            <option value="3">其他人员</option>
                        </select>
                    </div>
                </div>-->
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                    <div class="layui-input-block">
                        <input name="username" type="text" placeholder="账号" class="layui-input"
                               lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-password"></i></label>
                    <div class="layui-input-block">
                        <input name="password" type="password" placeholder="密码" class="layui-input"
                               lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-vercode"></i></label>
                    <div class="layui-input-block">
                        <div class="layui-row inline-block">
                            <div class="layui-col-xs7">
                                <input name="code" type="text" placeholder="验证码" class="layui-input"
                                       lay-verify="required" required/>
                            </div>
                            <div class="layui-col-xs5" style="padding-left: 10px;">
                                <img class="login-captcha" th:src="@{/user/images/captcha}">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <button lay-filter="login-submit" class="layui-btn layui-btn-fluid" lay-submit>登 录</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript" th:src="@{assets/libs/layui/layui.js}"></script>
<script>
    layui.use(['layer', 'form'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        // 表单提交
        form.on('submit(login-submit)', function (obj) {
            var  data=obj.field;
            $.ajax({
                type: "POST",
                url: "/user/userLogin",
                data: {
                     username: data['username']
                    , password: data['password'],
                    code:data['code']

                },
                dataType: "json",
                success: function (data) {
                    var res = data.data;
                    if (data.code == 0) {
                        layer.msg('登入成功！', {
                            icon: 1})
                        setTimeout(function () {
                            $(location).attr('href', 'admin/index');
                        },2000)
                    }
                    if (data.code == -1) {
                        layer.msg(res, {icon: 5});
                        $('.login-captcha').click();
                    }
                    if (data.code == -2) {
                        layer.msg(res, {icon: 5});
                        $('.login-captcha').click();
                    }
                    if (data.code == -3) {
                        layer.msg("验证码不正确", {icon: 5});
                        $('.login-captcha').click();
                    }
                }
            });
            return false;
        });
        $('.login-captcha').click(function () {
            this.src = this.src + '?t=' + (new Date).getTime();
        });
    });
</script>
</body>
</html>